package com.baway.net

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import javax.inject.Singleton

@Module //声明当前是一个Hilt模块
@InstallIn(SingletonComponent::class) //声明当前类的作用域是整个应用
object HttpHiltModel {


    @HttpClientAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideOkHttpClient(): OkHttpClient{
        return ClientManager.createOkHttpClient()
    }

    @HttpsClientAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideOkHttpsClient(): OkHttpClient{
        return ClientManager.createOkHttpsClient()
    }

    @HttpRetrofitAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideOkHttpRetrofit(@HttpClientAnnotation client: OkHttpClient): Retrofit{
        return RetrofitManager.getRetrofit(client)
    }

    @HttpsRetrofitAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideOkHttpsRetrofit(@HttpsClientAnnotation client: OkHttpClient): Retrofit{
        return RetrofitManager.getRetrofit(client)
    }


}